#ifndef CONTROLLER_H
#define CONTROLLER_H

#include "RegisterModule.h"
#include "OptionsModule.h"
#include "SessionModule.h"
#include "SdpModule.h"
#include "ClientAppDialogSetFactory.h"
#include "SessionData.h"

#include "MainWindow.h"

#include "resip/stack/SipStack.hxx"
#include "resip/dum/DialogUsageManager.hxx"
#include "resip/dum/MasterProfile.hxx"
#include "resip/dum/ClientAuthManager.hxx"
#include "resip/dum/KeepAliveManager.hxx"
#include "rutil/Log.hxx"
#include "rutil/Logger.hxx"

#include <string>

#define BASEPORT 5060
#define DESTPORT 5070
#define BASE_AUDIO_PORT 4000
#define BASE_VIDEO_PORT 5000
#define REG_TIME 70

class ConferenceModule;


class Controller
{
public:
	// Constructor & Destructor

	Controller();
	virtual ~Controller();

	// Memberfunctions

	void initialize();
	void cleanup();

	void start(std::string config, std::string codecs);

	void checkForResponse();
	void findOnlineContacts();

	// Update functions

	void changeContactStatus(std::string contact, bool online);
	void sentMessage(std::string message);
	void messageReceived(std::string contact, std::string message);
	void messageSucceeded(std::string contact);
	void inviteSelectedContact();
	void shutDown();

	//MAARTEN
	SdpModule* getSdpModule()
	{
		return m_sdpModule;
	}

private:
	// Initialization functions

	void createManagers();
	void createUserInterface();

	void initializeManagers();
	void initializeModules();

	void initializeClientAuthManager();
	void initializeClientAppDialogSetFactory();

	void initializeUserInterface();
	void initializeSdpContent();

	void initializeConference();

	// Startup functions

	void readConfigFile(std::string file);

	void registerOurself();
	void checkContactStatus(std::string contact);

	// Common functions

	std::string contactToNick(std::string contact);
	std::string nickToContact(std::string nick);
	ContactData* findContact(std::string contact);

	// Membervariables

	resip::SipStack* m_stack;
	resip::DialogUsageManager* m_dialogUsageManager;
	resip::SharedPtr<resip::MasterProfile>* m_masterProfile;
	std::auto_ptr<resip::ClientAuthManager>* m_clientAuthManager;
	std::auto_ptr<resip::KeepAliveManager>* m_keepAliveManager;
	std::auto_ptr<resip::AppDialogSetFactory>* m_clientAppDialogSetFactory;

	RegisterModule* m_registerModule;
	OptionsModule* m_optionsModule;
	SessionModule* m_sessionModule;
	SdpModule* m_sdpModule;

	MainWindow* m_userInterface;

	SessionData m_sessionData;

	ConferenceModule * m_sendModule;
	ConferenceModule * m_receiveModule;
};

#endif